Add dependencyQueueStrategy to paced mutations#1092
Draft
KyleAMathews wants to merge 5 commits intomainfrom
Draft
Add dependencyQueueStrategy to paced mutations#1092KyleAMathews wants to merge 5 commits intomainfrom
KyleAMathews wants to merge 5 commits intomainfrom
Conversation
This adds a new strategy for paced mutations that enables parallel execution
of mutations that affect different records, while still serializing mutations
that share dependencies (based on globalKey).
Key features:
- Mutations on different records run in parallel (no artificial serialization)
- Mutations on the same record are serialized in order
- Supports optional custom dependencies via getDependencies callback
- Rollback cascade still works correctly across dependent mutations
This addresses the use case where users want maximum parallelism without
sacrificing correctness - e.g., editing multiple independent items shouldn't
block on each other, but edits to the same item must be ordered.
Example usage:
```ts
const mutate = usePacedMutations({
onMutate: (vars) => collection.update(vars.id, ...),
mutationFn: async ({ transaction }) => api.save(transaction.mutations),
strategy: dependencyQueueStrategy()
})
// These run in parallel (different IDs):
mutate({ id: 1, title: 'A' })
mutate({ id: 2, title: 'B' })
// This waits for the first one (same ID):
mutate({ id: 1, title: 'C' })
```
🦋 Changeset detectedLatest commit: 4745e35 The changes in this PR will be included in the next version bump. This PR includes changesets to release 14 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
More templates
@tanstack/angular-db
@tanstack/db
@tanstack/db-ivm
@tanstack/electric-db-collection
@tanstack/offline-transactions
@tanstack/powersync-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
Contributor
|
Size Change: +778 B (+0.87%) Total Size: 90.3 kB
ℹ️ View Unchanged
|
Contributor
|
Size Change: 0 B Total Size: 3.35 kB ℹ️ View Unchanged
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds a new strategy for paced mutations that enables parallel execution of mutations that affect different records, while still serializing mutations that share dependencies (based on globalKey).
Key features:
This addresses the use case where users want maximum parallelism without sacrificing correctness - e.g., editing multiple independent items shouldn't block on each other, but edits to the same item must be ordered.
Example usage:
🎯 Changes
✅ Checklist
pnpm test:pr.🚀 Release Impact